<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>Redis 集合(Set) | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>Redis 集合(Set)</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Redis/">Redis</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis的Set是string类型的无序集合。集合成员是唯一的，这就意味着集合中不能出现重复的数据。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis 中 集合是通过哈希表实现的，所以添加，删除，查找的复杂度都是O(1)。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;集合中最大的成员数为 232 - 1 (4294967295, 每个集合可存储40多亿个成员)。</p>
<h2 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">edis 127.0.0.1:6379&gt; SADD runoobkey redis</div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD runoobkey mongodb</div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD runoobkey mysql</div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD runoobkey mysql</div><div class="line">(<span class="built_in">integer</span>) 0</div><div class="line">redis 127.0.0.1:6379&gt; SMEMBERS runoobkey</div><div class="line"> </div><div class="line">1) <span class="string">"mysql"</span></div><div class="line">2) <span class="string">"mongodb"</span></div><div class="line">3) <span class="string">"redis"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在以上实例中我们通过 <strong>SADD</strong> 命令向名为 <strong>runoobkey</strong> 的集合插入的三个元素。</p>
<h2 id="Redis-集合命令"><a href="#Redis-集合命令" class="headerlink" title="Redis 集合命令"></a>Redis 集合命令</h2><h3 id="1-Redis-Sadd-命令"><a href="#1-Redis-Sadd-命令" class="headerlink" title="1.Redis Sadd 命令"></a>1.Redis Sadd 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SADD key member1 [member2]</code> </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>向集合添加一个或多个成员</code><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Sadd 命令将一个或多个成员元素加入到集合中，已经存在于集合的成员元素将被忽略。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;假如集合 key 不存在，则创建一个只包含添加的元素作成员的集合。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;当集合 key 不是集合类型时，返回一个错误。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意：在Redis2.4版本以前， SADD 只接受单个成员值。</p>
<h4 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Sadd 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD KEY_NAME VALUE1..VALUEN</div></pre></td></tr></table></figure>
<h4 id="可用版本"><a href="#可用版本" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值"><a href="#返回值" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;被添加到集合中的新元素的数量，不包括被忽略的元素。</p>
<h4 id="实例-1"><a href="#实例-1" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"foo"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 0</div><div class="line">redis 127.0.0.1:6379&gt; SMEMBERS myset</div><div class="line">1) <span class="string">"hello"</span></div><div class="line">2) <span class="string">"foo"</span></div></pre></td></tr></table></figure>
<h3 id="2-Redis-Scard-命令"><a href="#2-Redis-Scard-命令" class="headerlink" title="2.Redis Scard 命令"></a>2.Redis Scard 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SCARD key</code> </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>获取集合的成员数</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Scard 命令返回集合中元素的数量。</p>
<h4 id="语法-1"><a href="#语法-1" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Scard 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SCARD KEY_NAME</div></pre></td></tr></table></figure>
<h4 id="可用版本-1"><a href="#可用版本-1" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-1"><a href="#返回值-1" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;集合的数量。 当集合 key 不存在时，返回 0 。</p>
<h4 id="实例-2"><a href="#实例-2" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"foo"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 0</div><div class="line">redis 127.0.0.1:6379&gt; SCARD myset</div><div class="line">(<span class="built_in">integer</span>) 2</div></pre></td></tr></table></figure>
<h3 id="3-Redis-Sdiff-命令"><a href="#3-Redis-Sdiff-命令" class="headerlink" title="3.Redis Sdiff 命令"></a>3.Redis Sdiff 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SDIFF key1 [key2]</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>返回给定所有集合的差集</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Sdiff 命令返回给定集合之间的差集。不存在的集合 key 将视为空集。</p>
<h4 id="语法-2"><a href="#语法-2" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Sdiff 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SDIFF FIRST_KEY OTHER_KEY1..OTHER_KEYN</div></pre></td></tr></table></figure>
<h4 id="可用版本-2"><a href="#可用版本-2" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-2"><a href="#返回值-2" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;包含差集成员的列表。</p>
<h4 id="实例-3"><a href="#实例-3" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"foo"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"world"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SDIFF myset myset2</div><div class="line">1) <span class="string">"foo"</span></div><div class="line">2) <span class="string">"bar"</span></div></pre></td></tr></table></figure>
<h3 id="4-Redis-Sdiffstore-命令"><a href="#4-Redis-Sdiffstore-命令" class="headerlink" title="4.Redis Sdiffstore 命令"></a>4.Redis Sdiffstore 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SDIFFSTORE destination key1 [key2]</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>返回给定所有集合的差集并存储在 destination 中</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Sdiffstore 命令将给定集合之间的差集存储在指定的集合中。如果指定的集合 key 已存在，则会被覆盖。</p>
<h4 id="语法-3"><a href="#语法-3" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Sdiffstore 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SDIFFSTORE DESTINATION_KEY KEY1..KEYN</div></pre></td></tr></table></figure>
<h4 id="可用版本-3"><a href="#可用版本-3" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-3"><a href="#返回值-3" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;结果集中的元素数量。</p>
<h4 id="实例-4"><a href="#实例-4" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"foo"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"world"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SDIFFSTORE destset myset myset2</div><div class="line">(<span class="built_in">integer</span>) 2</div><div class="line">redis 127.0.0.1:6379&gt; SMEMBERS destset</div><div class="line">1) <span class="string">"foo"</span></div><div class="line">2) <span class="string">"bar"</span></div></pre></td></tr></table></figure>
<h3 id="5-Redis-Sinter-命令"><a href="#5-Redis-Sinter-命令" class="headerlink" title="5.Redis Sinter 命令"></a>5.Redis Sinter 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SINTER key1 [key2]</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>返回给定所有集合的交集</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Sinter 命令返回给定所有给定集合的交集。 不存在的集合 key 被视为空集。 当给定集合当中有一个空集时，结果也为空集(根据集合运算定律)。</p>
<h4 id="语法-4"><a href="#语法-4" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Sinter 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SINTER KEY KEY1..KEYN</div></pre></td></tr></table></figure>
<h4 id="可用版本-4"><a href="#可用版本-4" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-4"><a href="#返回值-4" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;交集成员的列表。</p>
<h4 id="实例-5"><a href="#实例-5" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"foo"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"world"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SINTER myset myset2</div><div class="line">1) <span class="string">"hello"</span></div></pre></td></tr></table></figure>
<h3 id="6-Redis-Sinterstore-命令"><a href="#6-Redis-Sinterstore-命令" class="headerlink" title="6.Redis Sinterstore 命令"></a>6.Redis Sinterstore 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SINTERSTORE destination key1 [key2]</code> </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>返回给定所有集合的交集并存储在 destination 中</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Sinterstore 命令将给定集合之间的交集存储在指定的集合中。如果指定的集合已经存在，则将其覆盖。</p>
<h4 id="语法-5"><a href="#语法-5" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Sinterstore 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SINTERSTORE DESTINATION_KEY KEY KEY1..KEYN</div></pre></td></tr></table></figure>
<h4 id="可用版本-5"><a href="#可用版本-5" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-5"><a href="#返回值-5" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;交集成员的列表。</p>
<h4 id="实例-6"><a href="#实例-6" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"foo"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"world"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SINTERSTORE myset myset1 myset2</div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SMEMBERS myset</div><div class="line">1) <span class="string">"hello"</span></div></pre></td></tr></table></figure>
<h3 id="7-Redis-Sismember-命令"><a href="#7-Redis-Sismember-命令" class="headerlink" title="7.Redis Sismember 命令"></a>7.Redis Sismember 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SISMEMBER key member</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>判断 member 元素是否是集合 key 的成员</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Sismember 命令判断成员元素是否是集合的成员。</p>
<h4 id="语法-6"><a href="#语法-6" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Sismember 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SISMEMBER KEY VALUE</div></pre></td></tr></table></figure>
<h4 id="可用版本-6"><a href="#可用版本-6" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-6"><a href="#返回值-6" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果成员元素是集合的成员，返回 1 。 如果成员元素不是集合的成员，或 key 不存在，返回 0 。</p>
<h4 id="实例-7"><a href="#实例-7" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SISMEMBER myset1 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SISMEMBER myset1 <span class="string">"world"</span></div><div class="line">(<span class="built_in">integer</span>) 0</div></pre></td></tr></table></figure>
<h3 id="8-Redis-Smembers-命令"><a href="#8-Redis-Smembers-命令" class="headerlink" title="8.Redis Smembers 命令"></a>8.Redis Smembers 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SMEMBERS key</code> </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>返回集合中的所有成员</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Smembers 命令返回集合中的所有的成员。 不存在的集合 key 被视为空集合。</p>
<h4 id="语法-7"><a href="#语法-7" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Smembers 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SMEMBERS KEY VALUE</div></pre></td></tr></table></figure>
<h4 id="可用版本-7"><a href="#可用版本-7" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-7"><a href="#返回值-7" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;集合中的所有成员。</p>
<h4 id="实例-8"><a href="#实例-8" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"world"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SMEMBERS myset1</div><div class="line">1) <span class="string">"World"</span></div><div class="line">2) <span class="string">"Hello"</span></div></pre></td></tr></table></figure>
<h3 id="9-Redis-Smove-命令"><a href="#9-Redis-Smove-命令" class="headerlink" title="9.Redis Smove 命令"></a>9.Redis Smove 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SMOVE source destination member</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>将 member 元素从 source 集合移动到 destination 集合</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Smove 命令将指定成员 member 元素从 source 集合移动到 destination 集合。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SMOVE 是原子性操作。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果 source 集合不存在或不包含指定的 member 元素，则 SMOVE 命令不执行任何操作，仅返回 0 。否则， member 元素从 source 集合中被移除，并添加到 destination 集合中去。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;当 destination 集合已经包含 member 元素时， SMOVE 命令只是简单地将 source 集合中的 member 元素删除。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;当 source 或 destination 不是集合类型时，返回一个错误。</p>
<h4 id="语法-8"><a href="#语法-8" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Smove 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SMOVE SOURCE DESTINATION MEMBER</div></pre></td></tr></table></figure>
<h4 id="可用版本-8"><a href="#可用版本-8" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-8"><a href="#返回值-8" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果成员元素被成功移除，返回 1 。 如果成员元素不是 source 集合的成员，并且没有任何操作对 destination 集合执行，那么返回 0 。</p>
<h4 id="实例-9"><a href="#实例-9" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"world"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"foo"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SMOVE myset1 myset2 <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SMEMBERS myset1</div><div class="line">1) <span class="string">"World"</span></div><div class="line">2) <span class="string">"Hello"</span></div><div class="line">redis 127.0.0.1:6379&gt; SMEMBERS myset2</div><div class="line">1) <span class="string">"foo"</span></div><div class="line">2) <span class="string">"bar"</span></div></pre></td></tr></table></figure>
<h3 id="10-Redis-Spop-命令"><a href="#10-Redis-Spop-命令" class="headerlink" title="10.Redis Spop 命令"></a>10.Redis Spop 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SPOP key</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>移除并返回集合中的一个随机元素</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Spop 命令用于移除并返回集合中的一个随机元素。</p>
<h4 id="语法-9"><a href="#语法-9" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Spop 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SPOP KEY</div></pre></td></tr></table></figure>
<h4 id="可用版本-9"><a href="#可用版本-9" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-9"><a href="#返回值-9" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;被移除的随机元素。 当集合不存在或是空集时，返回 nil 。</p>
<h4 id="实例-10"><a href="#实例-10" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"world"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SPOP myset1</div><div class="line"><span class="string">"bar"</span></div><div class="line">redis 127.0.0.1:6379&gt; SMEMBERS myset1</div><div class="line">1) <span class="string">"Hello"</span></div><div class="line">2) <span class="string">"world"</span></div></pre></td></tr></table></figure>
<h3 id="11-Redis-Srandmember-命令"><a href="#11-Redis-Srandmember-命令" class="headerlink" title="11.Redis Srandmember 命令"></a>11.Redis Srandmember 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SRANDMEMBER key [count]</code> </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>返回集合中一个或多个随机数</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Srandmember 命令用于返回集合中的一个随机元素。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;从 Redis 2.6 版本开始， Srandmember 命令接受可选的 count 参数：</p>
<ul>
<li>如果 count 为正数，且小于集合基数，那么命令返回一个包含 count 个元素的数组，数组中的元素各不相同。如果 count 大于等于集合基数，那么返回整个集合。</li>
<li>如果 count 为负数，那么命令返回一个数组，数组中的元素可能会重复出现多次，而数组的长度为 count 的绝对值。</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;该操作和 SPOP 相似，但 SPOP 将随机元素从集合中移除并返回，而 Srandmember 则   仅仅返回随机元素，而不对集合进行任何改动。</p>
<h4 id="语法-10"><a href="#语法-10" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Srandmember 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SRANDMEMBER KEY [count]</div></pre></td></tr></table></figure>
<h4 id="可用版本-10"><a href="#可用版本-10" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-10"><a href="#返回值-10" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;只提供集合 key 参数时，返回一个元素；如果集合为空，返回 nil 。 如果提供了 count 参数，那么返回一个数组；如果集合为空，返回空数组。</p>
<h4 id="实例-11"><a href="#实例-11" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"world"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SRANDMEMBER myset1</div><div class="line"><span class="string">"bar"</span></div><div class="line">redis 127.0.0.1:6379&gt; SRANDMEMBER myset1 2</div><div class="line">1) <span class="string">"Hello"</span></div><div class="line">2) <span class="string">"world"</span></div></pre></td></tr></table></figure>
<h3 id="12-Redis-Srem-命令"><a href="#12-Redis-Srem-命令" class="headerlink" title="12.Redis Srem 命令"></a>12.Redis Srem 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SREM key member1 [member2]</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>移除集合中一个或多个成员</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>Redis Srem 命令用于移除集合中的一个或多个成员元素，不存在的成员元素会被忽略。</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;当 key 不是集合类型，返回一个错误。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 Redis 2.4 版本以前， SREM 只接受单个成员值。</p>
<h4 id="语法-11"><a href="#语法-11" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Srem 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SREM KEY MEMBER1..MEMBERN</div></pre></td></tr></table></figure>
<h4 id="可用版本-11"><a href="#可用版本-11" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-11"><a href="#返回值-11" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;被成功移除的元素的数量，不包括被忽略的元素。</p>
<h4 id="实例-12"><a href="#实例-12" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"world"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SREM myset1 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SREM myset1 <span class="string">"foo"</span></div><div class="line">(<span class="built_in">integer</span>) 0</div><div class="line">redis 127.0.0.1:6379&gt; SMEMBERS myset1</div><div class="line">1) <span class="string">"bar"</span></div><div class="line">2) <span class="string">"world"</span></div></pre></td></tr></table></figure>
<h3 id="13-Redis-Sunion-命令"><a href="#13-Redis-Sunion-命令" class="headerlink" title="13.Redis Sunion 命令"></a>13.Redis Sunion 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SUNION key1 [key2]</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>返回所有给定集合的并集</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Sunion 命令返回给定集合的并集。不存在的集合 key 被视为空集。</p>
<h4 id="语法-12"><a href="#语法-12" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Sunion 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SUNION KEY KEY1..KEYN</div></pre></td></tr></table></figure>
<h4 id="可用版本-12"><a href="#可用版本-12" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-12"><a href="#返回值-12" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;并集成员的列表。</p>
<h4 id="实例-13"><a href="#实例-13" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"world"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SUNION myset1 myset2</div><div class="line">1) <span class="string">"bar"</span></div><div class="line">2) <span class="string">"world"</span></div><div class="line">3) <span class="string">"hello"</span></div><div class="line">4) <span class="string">"foo"</span></div></pre></td></tr></table></figure>
<h3 id="14-Redis-Sunionstore-命令"><a href="#14-Redis-Sunionstore-命令" class="headerlink" title="14.Redis Sunionstore 命令"></a>14.Redis Sunionstore 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SUNIONSTORE destination key1 [key2]</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>所有给定集合的并集存储在 destination 集合中</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Sunionstore 命令将给定集合的并集存储在指定的集合 destination 中。如果 destination 已经存在，则将其覆盖。</p>
<h4 id="语法-13"><a href="#语法-13" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Sunionstore 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SUNIONSTORE DESTINATION KEY KEY1..KEYN</div></pre></td></tr></table></figure>
<h4 id="可用版本-13"><a href="#可用版本-13" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-13"><a href="#返回值-13" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;结果集中的元素数量。</p>
<h4 id="实例-14"><a href="#实例-14" class="headerlink" title="实例"></a>实例</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"world"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"hello"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset2 <span class="string">"bar"</span></div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SUNIONSTORE myset myset1 myset2</div><div class="line">(<span class="built_in">integer</span>) 1</div><div class="line">redis 127.0.0.1:6379&gt; SMEMBERS myset</div><div class="line">1) <span class="string">"bar"</span></div><div class="line">2) <span class="string">"world"</span></div><div class="line">3) <span class="string">"hello"</span></div><div class="line">4) <span class="string">"foo"</span></div></pre></td></tr></table></figure>
<h3 id="15-Redis-Sscan-命令"><a href="#15-Redis-Sscan-命令" class="headerlink" title="15.Redis Sscan 命令"></a>15.Redis Sscan 命令</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>SSCAN key cursor [MATCH pattern] [COUNT count]</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>迭代集合中的元素</code></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Redis Sscan 命令用于迭代集合键中的元素。</p>
<h4 id="语法-14"><a href="#语法-14" class="headerlink" title="语法"></a>语法</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;redis Sscan 命令基本语法如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SSCAN KEY [MATCH pattern] [COUNT count]</div></pre></td></tr></table></figure>
<h4 id="可用版本-14"><a href="#可用版本-14" class="headerlink" title="可用版本"></a>可用版本</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&gt;= 1.0.0</p>
<h4 id="返回值-14"><a href="#返回值-14" class="headerlink" title="返回值"></a>返回值</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;数组列表。</p>
<h4 id="实例-15"><a href="#实例-15" class="headerlink" title="实例"></a>实例</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 &quot;hello&quot;</div><div class="line">(integer) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 &quot;hi&quot;</div><div class="line">(integer) 1</div><div class="line">redis 127.0.0.1:6379&gt; SADD myset1 &quot;bar&quot;</div><div class="line">(integer) 1</div><div class="line">redis 127.0.0.1:6379&gt; sscan myset1 0 match h*</div><div class="line">1) &quot;0&quot;</div><div class="line">2) 1) &quot;hello&quot;</div><div class="line"> 2) &quot;h1&quot;</div></pre></td></tr></table></figure>

	

	
		<span class="different-posts"><a href="/2017/10/12/Redis/21. Redis 集合(Set)/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
